﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Middle_11_MaxArea
{
    class MainProject
    {
        static void Main(string[] args)
        {

            int s = MaxArea(new int[] { 1, 8, 6, 2, 5, 4, 8, 3, 7 });
            Console.WriteLine(s);

            Console.ReadKey();
        }
        public static int MaxArea(int[] height)
        {
            int firstIndex = 0;
            int secondIndex = height.Length-1;
            int area = 0;
            while (firstIndex< secondIndex)
            {
                area = Math.Max(area,(secondIndex - firstIndex) * Math.Min(height[firstIndex], height[secondIndex]));
                if (height[firstIndex] < height[secondIndex])
                {
                    firstIndex++;
                }
                else
                {
                    secondIndex--;
                }
            }
            return area;
        }
    }
}
